//////////////////////////////////////////////////////////////////////////
//	Name: CDXShaderManader.h
//	Purpose: Loads and maintains the shaders for the program
//	Created: October 21, 2009
//////////////////////////////////////////////////////////////////////////

#pragma once

#include <Windows.h>
#include <string.h>
#include <direct.h>


#include "CDXRenderWin32.h"

using std::string;

//////////////////////////////////////////////////////////////////////////
//Name: Struct DXSHADER
//Purpose: Holds a vertex and pixel shader. Also holds a buffer for loading.
//////////////////////////////////////////////////////////////////////////
struct DXSHADER
{
	D3DXHANDLE hTech; //Handle to a technique
	LPD3DXEFFECT theEffect; //Actual effect
	string szEffectName; //So we can do some sort of hooking up a shader to an object. Maybe we can look for the string in the vector of
						 //DXSHADERs and save the index to it?..
};

class CDXShaderManader
{
private:

	//////////////////////////////////////////////////////////////////////////
	//Deactivated!
	//////////////////////////////////////////////////////////////////////////
	CDXShaderManader();
	CDXShaderManader(const CDXShaderManader&);
	CDXShaderManader& operator=(const CDXShaderManader&);
	//////////////////////////////////////////////////////////////////////////

	CDXRenderWin32* m_DXR;      //I need the DX device, so this is a pointer to it.
public:

	~CDXShaderManader();

	//////////////////////////////////////////////////////////////////////////
	//Vector of shaders, use this for getting the index of a shader
	//////////////////////////////////////////////////////////////////////////
	std::vector<DXSHADER> m_vShaders; 

	//////////////////////////////////////////////////////////////////////////
	//	Name: GetInstance
	//	Purpose: Get the instance to the Shader Manager, only need one of em!
	//	In:
	//	Out:
	//	Return:	static &CDXShaderManader - only one instance.
	//////////////////////////////////////////////////////////////////////////
	static CDXShaderManader* GetInstance()
	{
		static CDXShaderManader instance;
		return &instance;
	}
	//////////////////////////////////////////////////////////////////////////
	//	Name: LoadShadersFromDirectory
	//	Purpose: Loads all the shaders from the "Shaders" directory
	//	In:
	//	Out:
	//	Return:	bool - true if successful.
	//////////////////////////////////////////////////////////////////////////
	bool LoadShadersFromDirectory();

	//////////////////////////////////////////////////////////////////////////
	//	Name: Init
	//	Purpose: Initializes the shader manager
	//	In:
	//	Out:
	//	Return:	bool - true if successful.
	//////////////////////////////////////////////////////////////////////////
	bool Init();

	//////////////////////////////////////////////////////////////////////////
	//	Name: Init
	//	Purpose: Initializes the shader manager
	//	In: strRootDirToLookIn - Where to look
	//		strExtToLookFor - What extension to look for
	//	Out: vListofFileName - fills out the vector of file names
	//	Return:	bool - true if successful.
	//////////////////////////////////////////////////////////////////////////
	void SearchDirectory(vector<string> &vListofFileName, string &strRootDirToLookIn, string &strExtToLookFor);
	
	//////////////////////////////////////////////////////////////////////////
	//	Name: GetShaderIndex
	//	Purpose: Get an index from the shader manager to attach to a render object.
	//	In: szShaderFileName - Filename to get an indexback. EX:"PixelMotionBlur.fx"
	//	Out: 
	//	Return:	int - index of the shaderx
	//////////////////////////////////////////////////////////////////////////
	int GetShaderIndex(string szShaderFileName);

	//////////////////////////////////////////////////////////////////////////
	//	Name: GetDXShader
	//	Purpose: Get a Shader from the shader manager.
	//	In: nIndex - index of the shader you want.
	//	Out: 
	//	Return:	DXSHADER - the directX shader.
	//////////////////////////////////////////////////////////////////////////
	DXSHADER* GetDXShader(int nIndex);

	
	//////////////////////////////////////////////////////////////////////////
	//Set Parameters in a Shader
	//TODO: Add Moar Uniforms.
	//////////////////////////////////////////////////////////////////////////
	void SetTexture(int nShaderID, int nTextureID, string szParameter);

	void SetMatrix(int nShaderID, string szParameter, CONST D3DXMATRIX* pMatrix);

	void SetVector(int nShaderID, string szParameter, CONST D3DXVECTOR4* pVec);
	
	void SetFloat(int nShaderID, string szParameter, CONST float fFloat);

};

//EOF